import http from "../axios";

// 登录
interface LoginParams {
	username: string;
	password: string;
	type: string;
	platform: string;
}
export const login = (data: LoginParams) => {
	return http.post("/cloudUser/login", data);
};

// 获取人员列表
interface GetUserListParams {
	pageNum: number;
	pageSize: number;
	queryFields?: {
		[k: string]: any;
	};
}
export const getUserList = (data: GetUserListParams) => {
	return http.post("/cloudUser/showPage", {
		...data,
		queryFields: {
			organizeCode: "BLUE",
			...(data.queryFields || {}),
		},
	});
};

// 添加用户
interface CreateUserParams {
	email?: string;
	headImg?: string;
	name: string;
	phone: string;
	username: string;
}
export const createUser = (data: CreateUserParams) => {
	return http.post("/cloudUser/addCloudUser", {
		...data,
		organizeCode: "BLUE",
	});
};

// 修改用户
interface UpdateUserParams {
	email?: string;
	headImg?: string;
	name: string;
	phone: string;
	username: string;
	userId: string;
}
export const updateUser = (data: UpdateUserParams) => {
	return http.post("/cloudUser/updateCloudUser", {
		...data,
		organizeCode: "BLUE",
	});
};

// 修改密码
interface EditPasswordParams {
	oldPassword: string;
	newPassword: string;
	userId: string;
}
export const editPassword = (data: EditPasswordParams) => {
	return http.post("/cloudUser/resetPassword", data);
};

// 修改状态
interface UpdateUserStatusParams {
	status: number;
	userId: string;
}
export const updateUserStatus = (data: UpdateUserStatusParams) => {
	return http.post("/cloudUser/changeStatus", data);
};

// 修改角色
interface editRoleParams {
	roleId: string;
	userId: string;
}
export const editRole = (data: editRoleParams) => {
	return http.post("/cloudUser/useRelRole", data);
};
